package com.cskaoyan.config2;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author stone
 * @date 2022/08/11 10:42
 */
@Configuration
public class DataSourceConfiguration2 {
    // 现在成员变量的值从哪里来 → 在springboot的配置文件里，通过键值对的key来引入对应的value
    @Value("${cskaoyan.datasource.driverClassName}")
    String driverClassName;
    @Value("${cskaoyan.datasource.url}")
    String url;
    @Value("${cskaoyan.datasource.username}")
    String username;
    @Value("${cskaoyan.datasource.password}")
    String password;
    @Bean
    public DataSource dataSource2() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
